var express = require('express');
var router = express.Router();
var path = require('path')
var formidable = require('formidable')
/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

// router.post('/upload',function(req,res,next){
//   var form = new formidable.IncomingForm()
//   form.uploadDir = path.join(__dirname,'..','public','upload')
//   form.parse(req,function(err,fields,files){
//     res.json({code:200,msg:'ok',data:fields})
//   })
//   userControll.sendOn(req,res)
  
// });

router.post('/upload', function (req, res, next) {
  var form = new formidable.IncomingForm()
  form.uploadDir = path.join(__dirname, '..', 'public', 'upload')  //设置上传文件的路径
  form.keepExtensions = true    //设置保留文件的扩展名
  //接受上传文件，并做后续处理
  form.parse(req, function (err, fields, files) {
    console.log('fields:', fields)
    console.log('files:', files)
    res.json({ code: 200, msg: 'ok' })
  })
});















module.exports = router;
